<!--
+----------------------------------------------------------------------
| 友得云客  - 开启房产营销新纪元
+----------------------------------------------------------------------
| Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
+----------------------------------------------------------------------
| Licensed 友得云客不是自由软件 未经允许不可移除相关版权
+----------------------------------------------------------------------
| Author: www.youdeyunke.com
+----------------------------------------------------------------------
-->
<template>
    <div>
        <el-form v-loading="loading" label-width="80px" label-position="right" size="small" :model="position">
            <el-form-item label="名称" required>
                <el-input maxlength="10" minlength="2" clearable v-model="position.name" placeholder="请输入位置名称"></el-input>
            </el-form-item>

            <!-- <el-form-item label="类型" required>
                <el-input maxlength="10" minlength="2" clearable v-model="position.cat"
                    placeholder="请输入类型:nav/banner/flash"></el-input>
            </el-form-item> -->

            <el-form-item label="说明">
                <el-input maxlength="20" minlength="0" clearable v-model="position.desc" placeholder="位置说明"></el-input>

            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" @click="$emit('cancle')" icon="el-icon-close">取 消</el-button>
            <el-button size="mini" type="primary" @click="submitHandle" icon="el-icon-check">确 定</el-button>
        </div>
    </div>
</template>
<script>
import { updatePagePosition, createPagePosition } from "@/api/page-position";
import HelpIcon from "@/components/HelpIcon";
export default {
    components: { HelpIcon },
    name: "position-form",
    data () {
        return {
            loading: false,
        };
    },
    props: {
        position: { type: Object, default: {} },
    },
    watch: {

    },
    created () { },

    methods: {
        submitHandle () {
            // 验证表单
            var formData = this.position;
            formData.cat = 'nav'
            if (!formData.name) {
                this.$message.error("请输入位置名称");
                return false;
            }
            this.loading = true
            if (this.position.id !== null) {
                updatePagePosition(formData).then((resp) => {
                    this.loading = false
                    if (resp.status === 0) {
                        this.$emit("change", resp.data);
                        this.$message({
                            type: "success",
                            message: "修改成功",
                        });
                    }
                });
                return;
            }
            createPagePosition(formData).then((resp) => {
                this.loading = false
                if (resp.status != 0) {
                    return
                }
                this.$emit("change", resp.data);
                this.$message({ type: "success", message: "创建位置成功！" });
            });
        },
    },
};
</script>
<style lang="scss" scoped>
.dialog-footer {
    width: 200px;
    height: 28px;
    margin-left: 279px;
}

.el-tooltip {
    position: absolute;
    right: -22px;
    top: 10px;
}
</style>